﻿#region License
/*Copyright (c) 2010 Andrew Collard (andrewcollard@hotmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/
#endregion

using System.IO;

namespace TorchView.Game
{
  public sealed class IncompleteQuest
  {
    public static uint Unknown1 { get; set; }
    public string Name { get; set; }
    public long NPCuuid { get; set; }
    public static uint Unknown2 { get; set; }
    public static int Unknown3 { get; set; }
    public static int Unknown4 { get; set; }
    
    public static IncompleteQuest Read(BinaryReader reader)
    {
      IncompleteQuest quest = new IncompleteQuest();
      Unknown1 = reader.ReadUInt32();
      quest.Name = SVTHelper.ReadString(reader);
      quest.NPCuuid = reader.ReadInt64();
      Unknown2 = reader.ReadUInt32();
      Unknown3= reader.ReadInt32();
      Unknown4 = reader.ReadInt32();

      ReadUnknown7(reader);
      ReadUnknown7(reader);
      ReadUnknown7(reader);
      ReadUnknown7(reader);

      ReadUnknown8(reader);
      ReadUnknown8(reader);
      ReadUnknown8(reader);

      return quest;
    }

    private static Unknown7[] ReadUnknown7(BinaryReader reader)
    {
      var count = reader.ReadInt32();
      if (count < 0)
        count = 0;
      Unknown7[] unknown7s = new Unknown7[count];
      for (int i = 0; i < count; i++)
        unknown7s[i] = Unknown7.Read(reader);
      return unknown7s;
    }

    private static Unknown8[][] ReadUnknown8(BinaryReader reader)
    {
      var a = reader.ReadInt32();
      if (a < 0)
        a = 0;
      Unknown8[][] unknown8s = new Unknown8[a][];
      for (int y = 0; y < a; y++)
      {
        var b = reader.ReadInt32();
        if (b < 0)
          b = 0;
        Unknown8[] unknown8s2 = new Unknown8[b];
        for (int x = 0; x < b; x++)
          unknown8s2[x] = Unknown8.Read(reader);
        unknown8s[y] = unknown8s2;
      }
      return unknown8s;
    }

    public override string ToString()
    {
      return Name;
    }
  }
}
